﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpreadsheetLight;

namespace UtilsLib.UtilsFile
{
    /// <summary>
    /// Acts like basic string, with more methods for SpreasheetLight, and applies style.
    /// </summary>
    public class FileColumn : StringComparer
    {
        //Fields
        private string _columnValue;
        private SLStyle _style;


        //Properties
        public string ColumnValue
        {
            get { return _columnValue; }
            set { _columnValue = value; }
        }
        public SLStyle Style
        {
            get { return _style; }
            set { _style = value; }
        }

        //Constructors
        public FileColumn()
        {
            _columnValue = "";
            _style = new SLStyle();
        }
        public FileColumn(string value)
        {
            _columnValue = value;
            _style = new SLStyle();
        }

        public FileColumn(string value, SLStyle style)
        {
            _columnValue = value;
            _style = style;
        }

        //Conversion operators
        public static implicit operator string(FileColumn fc)
        { return (fc == null) ? "" : fc.ToString(); }
        public static implicit operator FileColumn(string s)
        { return new FileColumn(s); }

        //Overrides 
        /// <summary>
        /// Returns column Value (override).
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            //return base.ToString();
            //SLRstType rst = new SLRstType();
            //if (_style != null && _style.Font != null)
            //{
            //rst.AppendText(_columnValue, _style.Font);
            //return rst.GetRuns();
            //}
            return _columnValue;

        }
        public string ToLower()
        {
            return _columnValue.ToLower();
        }

        /// <summary>
        /// Returns equal of objetcs (override)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            //return base.Equals(obj);
            return _columnValue.Equals(obj);
        }
        public override bool Equals(string x, string y)
        {
            return x.Equals(y);
        }

        /// <summary>
        /// Basic Compare method
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public override int Compare(string x, string y)
        {
            return x.CompareTo(y);
        }

        /// <summary>
        /// Returns hashcode of object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override int GetHashCode()
        {
            //return base.GetHashCode();
            return _columnValue.GetHashCode();
        }
        public override int GetHashCode(string obj)
        {
            return obj.GetHashCode();
        }
    }
}
